package com.weasel.im.server.initializer;

import com.weasel.im.common.cache.LeaveMessageCache;
import com.weasel.im.common.manager.IMSessionManager;
import com.weasel.im.common.manager.LeaveMessageCacheManager;
import com.weasel.im.common.manager.UserSessionRelationManager;
import com.weasel.im.server.handler.JettyIMServerHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.serialization.ClassResolvers;
import io.netty.handler.codec.serialization.ObjectDecoder;
import io.netty.handler.codec.serialization.ObjectEncoder;

/**
 * Created by Dylan on 2015/11/27.
 */
public class JettyIMServerInitializer extends AbstractChannelInitializer {


    public JettyIMServerInitializer(IMSessionManager sessionManager, UserSessionRelationManager relationManager, LeaveMessageCacheManager leaveMessageCacheManager) {
        super(sessionManager, relationManager, leaveMessageCacheManager);
    }

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        socketChannel.pipeline()
                     .addLast(new ObjectDecoder(1024*1024, ClassResolvers.weakCachingConcurrentResolver(this.getClass().getClassLoader())))
                     .addLast(new ObjectEncoder())
                     .addLast(new JettyIMServerHandler(sessionManager,relationManager,leaveMessageCacheManager));
    }

}
